package it.mp.multitask.utility;

import java.io.Serializable;
import java.util.Comparator;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;


public class PackageInfoComparator implements Serializable, Comparator<PackageInfo> {
	private PackageManager pm = null;
	private static final long serialVersionUID = -6700403096228788434L;

	public PackageInfoComparator(PackageManager pm) {
		this.pm = pm;
	}

	public int compare(PackageInfo pInfo1, PackageInfo pInfo2) {
		String app1 = null;
		String app2 = null;
		try {
			app1 = (String) pm.getApplicationLabel(pm.getApplicationInfo(pInfo1.packageName, 0));
		} catch (Exception e) {
		}
		try {
			app2 = (String) pm.getApplicationLabel(pm.getApplicationInfo(pInfo2.packageName, 0));
		} catch (Exception e) {
		}

		if ((app1 == null) || (app2 == null)) {
			return 0;
		} else {
			return app1.compareTo(app2);
		}
	}

}
